package com.cody.controller.passage;

import com.cody.entity.Answer;
import com.cody.entity.Passage;
import com.cody.service.PassageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Cody
 * @date 2021/4/8 - 18:16
 */
@Controller
public class PassageController {
    @Autowired
    private PassageService passageService;

    @RequestMapping("/passage/del")
    @ResponseBody
    public Map<String, String> del(@RequestParam(required = false, name = "passageId") int passageId) {
        Map<String, String> map = new HashMap<>();
        boolean flag =    passageService.delPassageByPassageId(passageId);
        if(flag){
            map.put("msg","删除成功");
        }
        return map;
    }

    @RequestMapping("/passage/update")
    public String update(@RequestParam(required = false, name = "passageId") String passageId,
                         @RequestParam(required = false, name = "passageContent") String passageContent) {

        Passage passage = passageService.querySinglePassage(Integer.parseInt(passageId));
        passage.setPassageContent(passageContent);
        passageService.updPassageInfo(passage);
        return "redirect:/admin/index";
    }
}
